package si.yun.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import si.yun.dao.NavigationDao;
import si.yun.entity.NavigationUserInfo;
import si.yun.service.NavigationService;

import java.util.List;
import java.util.Map;

/**
 * @author: DZQ
 * @description: TODO
 * @date: 2021/7/28 19:40
 * @return
 */
@Service
public class NavigationServiceImpl implements NavigationService {

    @Autowired
    private NavigationDao dao;

/**
 * @author: DZQ
 * @description:
 * @date: 2021/7/29 10:34
 * @return
 */

    @Override
    public List<Map<String, Object>> selNavigation() {
        List<Map<String, Object>> getNavigationFather=dao.selNavigationFather(null);
        for(Map<String, Object> i:getNavigationFather){
            int id = (int) i.get("menu_id");
            List<Map<String, Object>> navigationSon = selNavigationSon(id);
            if(navigationSon.size()==0){
                continue;
            }
            i.put("children",navigationSon);
        }
        return getNavigationFather;
    }

    /**
     * @Author : dzq
     * @Date : 2021/7/28 12:40
     * @Param : [id]
     * @Return : java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     */
    public List<Map<String, Object>> selNavigationSon(int id) {
        List<Map<String, Object>> getNavigationFather=dao.selNavigationFather(id);
        for(Map<String, Object> i:getNavigationFather){
            int idSon = (int) i.get("menu_id");
            List<Map<String, Object>> navigationSon = dao.selNavigationFather(idSon);
            if(navigationSon.size()==0){
                continue;
            }
            i.put("children",navigationSon);

        }
        return getNavigationFather;
    }
    /**
     * @Description  获取用户登录信息
     * @return si.yun.entity.NavigationUserInfo 
     * @Date 2021/9/13 11:51
     **/
    @Override
    public NavigationUserInfo selUserInfo(Integer userId) {
        NavigationUserInfo nowInfo = dao.selUserNowInfo(userId);
        NavigationUserInfo aginInfo = dao.selUserAginInfo(userId);
        nowInfo.setLoginAginDate(aginInfo.getLoginAginDate());
        return nowInfo;
    }
}
